package com.hp.goods_service.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hp.common_api.entity.Brand;
import com.hp.goods_service.service.IBrandService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class BrandController {

    @Autowired
    private IBrandService brandService;

    @GetMapping("brands/category/{cid}")
    public ResponseEntity<List<Brand>> getBrandsByCategoryId(@PathVariable Long cid){
        return ResponseEntity.ok(brandService.getBrandsByCategoryId(cid));
    }

    @GetMapping("brand/{id}")
    public ResponseEntity<Brand> getBrandById(@PathVariable Long id){
        Brand brand = brandService.getOne(
                new QueryWrapper<Brand>().lambda().eq(Brand::getId, id));
        return ResponseEntity.ok(brand);
    }
}
